package com.zhss.dfs.common;

import com.google.common.io.Resources;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class PropertiesUtil {
    public static Map<String, String> propertiesToMap(String fileName) {
        Properties properties = new Properties();
        try {
            properties.load((BufferedInputStream) Resources.getResource(fileName).getContent());
        } catch (IOException e) {
            e.printStackTrace();
        }
        Set<Object> keys = properties.keySet();
        Map<String, String> map = new HashMap<>();
        for (Object k : keys) {
            map.put((String) k, (String) properties.get(k));
        }
        return map;
    }

    public static void main(String[] args) {
        Map<String, String> stringStringMap = propertiesToMap("dfs-namenode.properties");
        System.out.println(stringStringMap);
    }
}
